// pages/guanli/guanli.js
var app = getApp()
let api = require('../../../api/api.js')
var util = require("../../../utils/util.js")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hide:true,
    selectIndex:10000,
    isfix:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (data) {
    var that = this
    that.setData({
      data:data
    })
    
  },
  foucus:function(e){
    this.setData({
      hide:false
    })
  },
  blur:function(e){
    this.setData({
      hide:true
    })
  },
  clear:function(){
    var that = this
    var data = {}
    data.id = app.globalData.userInerInfo.id
    data.mobile = app.globalData.userInerInfo.number
    api.userlevel(data, res => {
      console.log(res)
      that.setData({
        searchValue: "",
        content: res.data.result.level
      })
    })
  },
  workContent:function(e){
    console.log(e)
    var id = e.currentTarget.dataset.id
    var mobile = e.currentTarget.dataset.number
    wx.navigateTo({
      url: '../user_order/user_order?id=' + id + "&mobile=" + mobile + "&level=1" + "&type=1",
    })
  },
  search: function (e){
    var that = this
    var data = {}
    data.name = e.detail.value
    data.id = app.globalData.userInerInfo.id
    data.mobile = app.globalData.userInerInfo.number
    api.userlevel(data, res => {
      console.log(res)
      that.setData({
        content: res.data.result.level
      })
    })
  },
  navigator:function(){
    var that = this
    var data = {}
    // data.id = app.globalData.userInerInfo.id
    data.mobile = app.globalData.userInerInfo.number
    console.log(data)
    wx.navigateTo({
      // url: '/pages/A/store/store?data.id=' + data.id + "&data.mobile=" + data.mobile,
      url: '/pages/A/store/store?data.mobile=' + data.mobile,
    })
  },

  // 登录按钮点击事件
  deleteList: function () {
    wx.navigateTo({
      url: '../xiugai/xiugai',
    })
  },
  delWork:function(e){
    console.log(e)
    var id = e.currentTarget.dataset.id;
    var mobile = e.currentTarget.dataset.mobile
    util.navigateTo("/pages/A/xiugai/xiugai", { id: id, mobile: mobile})
    this.setData({
      selectIndex: 10000
    })
  },
  confirm:function(e){
    var that = this
    var data = {}
    data.id = app.globalData.userInerInfo.id
    data.mobile = app.globalData.userInerInfo.number
    api.userlevel(data, res => {
      console.log(res)
      that.setData({
        content: res.data.result.level
      })
    })
  },
  generate:function(e){
    var id = e.currentTarget.dataset.id;
    var img = e.currentTarget.dataset.img;
    util.navigateTo("../generate/generate", { id: id,img:img})
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    wx.request({
      url: 'https://www.900yeah.com/api/Distribution/newlist',
      data: {
        mobile: app.globalData.userInerInfo.number,
        id: app.globalData.userInerInfo.id
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        that.setData({
          userInfo: res.data.result,
          userInfo1: res.data.result.partner,
          result: res.data.result.partner
        })
      },
    })
    var data = this.data.data
    api.userlevel(data, res => {
      console.log(res)
      that.setData({
        content: res.data.result.level,
        content_list: res.data.result.list
      })
    })
  },

  onPageScroll(e) {
    let that = this
    let scrollTop = this.data.scrollTop
    // let swiperTop = this.swiperTop
      // 上拉
      if (e.scrollTop > scrollTop && e.scrollTop > 0) {
        that.setData({
          isfix: false
        })
      } else {
        // 下拉
        that.setData({
          isfix: true
        })
      }
    that.data.scrollTop = e.scrollTop
  },
})